package com.example.bgxqmanage.mapper;

import com.example.bgxqapi.domain.dao.Label;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author lizijian
 */
@Mapper
public interface LabelDao {


  /**
   * 查询指定动态id数组的标签
   * @param activityIds 动态id数组
   * @return
   */
  @Select("<script>SELECT label.id,label.content,activity_label.activity_id FROM label,activity_label WHERE "
      + "activity_label.activity_id IN (<foreach collection = 'list' item = 'item' separator = ','>#{item}</foreach>) AND label.id=activity_label.label_id</script>")
  List<Label> getLabelsByActivityIds(@Param("list") int [] activityIds);


  /**
   * 未审核标签列表
   * @param page
   * @return
   */
  @Select("SELECT * FROM label WHERE is_audit = 0")
  List<Label> unAuditLabelList(int page);

  /**
   * 标记标签已审核
   * @param labelId
   */
  @Update("UPDATE label SET is_audit =1 WHERE id = #{id}")
  void passLabel(int labelId);

  /**
   * 删除标签
   * @param labelId
   */
  @Delete("DELETE FROM label WHERE id = #{id}")
  void deleteLabel(int labelId);

  /**
   * 删除动态标签
   * @param labelId
   */
  @Delete("DELETE FROM activity_label WHERE activity_label.label_id = #{id}")
  void deleteActivityLabel(int labelId);

}
